package leetcodecompetition.S118;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-11-25-22:38
 * @Description: 1.0
 */
public class T100138 {
    public int maximizeSquareHoleArea(int n, int m, int[] hBars, int[] vBars) {
        Arrays.sort(hBars);
        Arrays.sort(vBars);
        return (int) Math.pow(Math.min(getMaxLen(hBars), getMaxLen(vBars)) + 1, 2);
    }

    public int getMaxLen(int[] nums) {
        int maxLen = 0, len = 0, pre = -1;
        for (int num : nums) {
            if (num == pre + 1) {
                len++;
            } else {
                len = 1;
            }
            pre = num;
            maxLen = Math.max(maxLen, len);
        }
        return maxLen;
    }
}
